{% block head %}
	<link href="{{ path }}js/plugins/datatables/DT_bootstrap.css" rel="stylesheet">
	<link href="{{ path }}js/plugins/responsive-tables/responsive-tables.css" rel="stylesheet"> 
    
    <script src="{{ path }}js/demos/demo.tables.js"></script>
    <script src="{{ path }}js/plugins/datatables/jquery.dataTables.js"></script>
    <script src="{{ path }}js/plugins/datatables/DT_bootstrap.js"></script>
	<script src="{{ path }}js/plugins/responsive-tables/responsive-tables.js"></script>
{% endblock %}

<script type="text/javascript">
	function OnSubmitForm(){
        if(document.pressed == 'ImprimirCal'){
            document.frm_historial.action ="/cartera/estudiantes/calendario/imprimir/";
            return true;
        }
        
        if(document.pressed == 'EliminarHis'){
        	if($('input:checked').length < 1){
                alert("Debe seleccionar al menos un formulario.");
                return false;
            }
            document.frm_matriculas.action ="/cartera/estudiantes/matriculas/borrar/";
            document.frm_matriculas.target ="_self";
            return true;
        }
        
        if(document.pressed == 'ImprimirHis'){
            document.frm_matriculas.action ="/cartera/estudiantes/historial/imprimir/";
            document.frm_matriculas.target ="_blank";
            return true;
        }
		
		if(document.pressed == 'ImprimirAcu'){
			
            document.frm_matriculas.action ="/cartera/estudiantes/historial/imprimirAcuerdo/";
            document.frm_matriculas.target ="_blank";
            return false;
        }
    }
	
	$( $(".acc_edit[id^='edit']") ).click(function() {
		matricula_id = $(this).attr('matricula');
		$.ajax({
				url: "/cartera/estudiantes/matriculas/editar/",
				type: "POST",
				data : {matricula_id:matricula_id,
						csrfmiddlewaretoken : $('#csrf_token >div >input').attr("value")
						 },
				dataType: "html",
				success: function(datos) {
					$('#editar_matricula').html(datos);
				}
			});
	});
	

	$( $(".acc_mat[id^='mat']") ).click(function() {
		matricula_id = $(this).attr('matricula');
        $.ajax({
                url: "/cartera/estudiantes/calendario/",
                type: "POST",
                data : {matricula_id:matricula_id,
                        csrfmiddlewaretoken : $('#csrf_token >div >input').attr("value")
                         },
                dataType: "html",
                success: function(datos) {
                    $('#historial').html(datos);
                    $('#facultad').attr('value', 0);
                    $('#periodo').attr('value', 0);
                    $('#semestre').attr('value', 0);
                    $('#valor-credito').attr('value', 0);
                    $('#cuotas').attr('value', 0);
                }
            });
    });
    
	
	$( $(".acc_imp[id^='imp']") ).click(function() {
		url = "/cartera/estudiantes/matricula/acuerdo/" + $(this).attr('matricula');
		window.open(url);
	});
	
	$( $(".paz_imp[id^='imp']") ).click(function() {
			url = "/cartera/estudiantes/matricula/pazysalvo/" + $(this).attr('matricula');
			window.open(url);
		});
</script>

{% load humanize %}

<script type="text/javascript">
</script>
<div class="widget widget-table">
<div class="widget-header">						
    <h3>
        <i class="icon-th-list"></i>
        Histórico de matrículas		
    </h3>
</div> <!-- /widget-header -->
<div class="widget-content">
<form name="frm_matriculas" id="frm_matriculas" action="/cartera/estudiantes/matriculas/borrar/" method="post" target="_blank" onsubmit="return OnSubmitForm();">
	{% csrf_token %}
    <input type="hidden" id="id_est" name="id_est" value="{{ estudiante.id }}"/>
	<table class="table table-striped table-bordered table-highlight">
        <thead>
            <tr>
                <th width="2%" align="center"></th>
                <th width="8%" align="center">Fecha</th>
                <th width="5%" align="center">Periodo</th>
                <th width="20%" align="center">Facultad</th>
                <th width="5%" align="center">Semestre</th>
                <th width="10%" align="center">Crédito</th>
				<th width="10%" align="center">Descuento</th>
				<th width="10%" align="center">Intereses</th>
                <th width="5%" align="center">Cuotas</th>
                <th width="10%" align="center">Saldo</th>
                <th width="15%" align="center">Acciones</th>
            </tr>
        </thead>
        <tbody>
        {% for mat in matricula %}
        <tr class="{% cycle '' 'odd' %}">
        	<td><input type="checkbox" id="chk_{{mat.id}}" name="chk_{{mat.id}}" value="true"/></td>
            <td>{{ mat.fecha|date:'d-m-Y' }}</td>
            <td>{{ mat.periodo.nombre }}</td>
            <td>{{ mat.facultad.nombre }}</td>
            <td style="text-align:center">{{ mat.semestre }}</td>
            <td style="text-align:right">{{ mat.valor_credito|intcomma }}</td>
			<td style="text-align:right">{{ mat.valor_descuento|intcomma|default_if_none:"" }}</td>
			<td style="text-align:right">{{ mat.intereses|intcomma|default_if_none:"" }}</td>
            <td style="text-align:center">{{ mat.cuotas }}</td>
            <td style="text-align:right">{{ mat.saldo|intcomma }}</td>
            <td style="text-align:center">
             	<a href="#modalHistorial"  id="mat{{ mat.id }}" matricula="{{ mat.id }}" data-toggle="modal" class="acc_mat">
                        <img src="{{ path }}images/24x24/calculator.png"  title="Ver historial de pagos y cartera."/>
                </a>
                <a href="#modalEditarMatricula"  id="edit{{ mat.id }}" matricula="{{ mat.id }}" data-toggle="modal" class="acc_edit">
                        <img src="{{ path }}images/24x24/edit.png"  title="Editar registro de matrícula."/>
				</a>
				<a href="javascript:;" id="imp{{ mat.id }}" matricula="{{ mat.id }}" class="acc_imp"><img src="{{ path }}images/24x24/printer.png" title="Imprimir acuerdo de pago." value="ImprimirAcu"/>
				</a>
				{% if mat.saldo == 0 %}
				<a href="javascript:;" id="imp{{ mat.id }}" matricula="{{ mat.id }}" class="paz_imp">
					<img src="{{ path }}images/24x24/paz_y_salvo.png" title="Imprimir paz y salvo." value="ImprimirPaz"/>
				</a>
				{% endif %}
            </td>
        </tr>
    {% endfor %}
        </tbody>
    </table>
    <div class="modal-footer">
        <button type="submit" class="btn btn-primary btn-medium" id="btn_eliminarHis" onclick="document.pressed=this.value" value="EliminarHis">Eliminar</button>
        <button type="submit" class="btn btn-primary btn-medium" id="btn_reporteHis" onclick="document.pressed=this.value" value="ImprimirHis">Reporte</button>
    </div>
    </form>
</div> <!-- /. widget-content -->
</div> <!-- /. widget-table -->